<?php

// process.php by Matt Fritz
// April 13, 2010
// Handles the processing of various submitted forms and operations

require_once("database.php");

// re-direct to a page given a task as a parameter
function processRedirect($task)
{
	if($task == "managecourses")
	{
		print Header("Location: manage_courses.php");
	}
	else if($task == "assigncourses")
	{
		print Header("Location: assign_courses.php");
	}
	else if($task == "help")
	{
		print Header("Location: help.php");
	}
	else if($task == "home")
	{
		print Header("Location: index.php");
	}
	else if($task == "logout")
	{
		print Header("Location: logout.php");
	}
}

// handle requests that are submitted to process.php
function dispatchRequest()
{
	if(!empty($_POST['formName']))
	{
		if($_POST['formName'] == "tasksForm")
		{
			// re-direct to a given task
			processRedirect(addslashes($_POST['tasksSelect']));
		}
		else if($_POST['formName'] == "addCourse")
		{
			// add the given course to the database
			addCourse(sanitizeInput($_POST['courseDept']), sanitizeInput($_POST['courseNum']), sanitizeInput($_POST['courseName']), sanitizeInput($_POST['courseType']), sanitizeInput($_POST['courseStudents']), sanitizeInput($_POST['courseNotes']));
		}
		else if($_POST['formName'] == "editCourse")
		{
			// edit the given course in the database
			editCourse(sanitizeInput($_POST['courseID']), sanitizeInput($_POST['courseDept']), sanitizeInput($_POST['courseNum']), sanitizeInput($_POST['courseName']), sanitizeInput($_POST['courseType']), sanitizeInput($_POST['courseStudents']), sanitizeInput($_POST['courseNotes']));
		}
		else if($_POST['formName'] == "deleteCourse")
		{
			// delete the given course from the database
			removeCourse(sanitizeInput($_POST['courseID']));
		}
		else if($_POST['formName'] == "assignCourse")
		{
			// assign the given instructor to the given course
			assignCourse(sanitizeInput($_POST['instructorID']), sanitizeInput($_POST['courseID']), sanitizeInput($_POST['term']));
		}
		else if($_POST['formName'] == "removeCourseAssignment")
		{
			// remove the given course assignment
			removeCourseAssignment(sanitizeInput($_POST['instructorID']), sanitizeInput($_POST['courseID']), sanitizeInput($_POST['term']));
		}
	}
}

dispatchRequest(); // handle requests to this library

?>